<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>房屋信息查询</title>
	</head>
	<body>
	<h2>房屋信息查询</h2>
	<a href="houseinfoadd.jsp">发布房源</a>
	<br />
	<input type="hidden" value="1" name="startPageNo"/>
	<table border="1" cellspacing="0" width="600">
		<thead>
			<tr>
				<th>序号</th>
				<th>描述</th>
				<th>户型</th>
				<th>租金</th>
				<th>发布时间</th>
			</tr>
		</thead>
		<tbody id="houseinfoBody">
		</tbody>
	</table>
	<div id="paging">
	</div>
	</body>
	<script type="text/javascript" src="statics/jquery-1.8.3.js"></script>
	<script type="text/javascript">
		$(function(){
			loadTableData();
		});
		function loadTableData(){
			$.ajax({
				url : 'houseinfo/list',
				type : 'post',
				data : {startPageNo : $("input[name=startPageNo]").val()},
				dataType : 'json',
				success : function(response){
					var datas = response.data;
					var strTable = "";
					for (var i = 0; i < datas.length; i++) {
			  strTable+="<tr>"+
							"<td>"+datas[i]['houseId']+"</td>"+
							"<td>"+datas[i]['houseDesc']+"</td>"+
							"<td>"+datas[i]['housetype']['typeName']+"</td>"+
							"<td>"+datas[i]['monthlyRent']+"</td>"+
							"<td>"+datas[i]['publishDate']+"</td>"+
						"</tr>";
					}
					$("#houseinfoBody").html(strTable);
					//拼接分页信息
					var strPaging = "";
					var startPageNo = response.currentPageNo;
					var totalPageCount = response.totalPageCount;
					if (startPageNo > 1) {
			strPaging+="<a href=\"javascript:page_nav(1);\">首页</a>&nbsp;&nbsp;"+
					   "<a href=\"javascript:page_nav("+(startPageNo-1)+");\">上一页</a>&nbsp;&nbsp;";
					} else {
			strPaging+="首页&nbsp;&nbsp;上一页&nbsp;&nbsp;";
					}
					if (startPageNo < totalPageCount) {
			strPaging+="<a href=\"javascript:page_nav("+(startPageNo+1)+");\">下一页</a>&nbsp;&nbsp;"+
					   "<a href=\"javascript:page_nav("+totalPageCount+");\">末页</a>&nbsp;&nbsp;";
					} else {
			strPaging+="下一页&nbsp;&nbsp;末页&nbsp;&nbsp;";
					}
					strPaging+="第"+startPageNo+"页&nbsp;&nbsp;共"+totalPageCount+"页&nbsp;&nbsp;";
					$("#paging").html(strPaging);

				}
			});
		}
		
		function page_nav(pageNo){
			$("input[name=startPageNo]").val(pageNo);
			loadTableData();
		}
	</script>
</html>
